package com.i5tong.mvpdemo.presenter;

import android.content.Context;

import com.i5tong.mvpdemo.model.WeatherInfoModel;
import com.i5tong.mvpdemo.model.WeatherInfoModelInterface;
import com.i5tong.mvpdemo.view.WeatherInterface;
import com.koushikdutta.async.future.FutureCallback;
import com.koushikdutta.ion.Ion;

/**
 * Created by Steven on 15/2/1.
 */
public class WeatherPresenter {
    private Context context;

    private WeatherInfoModelInterface weatherInfoModelInterface;
    private WeatherInterface weatherInterface;

    public WeatherPresenter(Context context) {
        this.context = context;
        this.weatherInterface = (WeatherInterface)context;
        this.weatherInfoModelInterface = new WeatherInfoModel();
    }


    public void queryWeatherInfo() {
        Ion.with(context).load("http://www.weather.com.cn/data/sk/101010100.html")
                .asString()
                .setCallback(new FutureCallback<String>() {
                    @Override
                    public void onCompleted(Exception e, String result) {
                        weatherInfoModelInterface.setWeatherInfoContainer(result);
                        weatherInterface.onWeatherLoad(weatherInfoModelInterface.getWeatherInfoContainer());
                    }
                });
    }
}
